package com.season.seasonStudy.javase.j_016_dom4j;

import java.io.File;
import java.util.List;




import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class Test {

	public static void main(String[] args) {
		
		SAXReader reader=new SAXReader();
		try {
			Document doc=reader.read(new File("src/myxml.xml"));
			System.out.println(doc.getName());
			Element root=doc.getRootElement();
			System.out.println(root.getName());
			System.out.println(root.getNodeTypeName());
			System.out.println(root.getTextTrim());
			System.out.println(root.attribute("name").getText());
			/*List<Element> list=root.elements("name");
			System.out.println("length:"+list.size());
			for (int i = 0; i < list.size(); i++) {
				System.out.println(list.get(i).attributeValue("id"));
			}*/
			/*List<Node> list=root.selectNodes("book/name");
			System.out.println("length:"+list.size());
			
			for (Node node : list) {
				System.out.println(node.getText());
			}*/
			//List<Node> list=root.selectNodes("book[@id!='2']/author");
			List<Node> list=root.selectNodes("descendant::name");
			for (Node node : list) {
				System.out.println(((Element)node).getText());
			}
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
	}

}
